package com.xbh.dms.controller;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.xbh.dms.service.LoginSrv;
import com.xbh.validator.LoginValidator;
import com.xbh.zzzTest.RetTest;

import java.util.HashMap;


/**
 * @LoginController: 这是一个登录的Action
 * @author: ZBoHang
 * @time: 2021/8/5 10:40
 */
@Path("/login")
public class LoginController extends Controller {

    @Inject
    LoginSrv loginSrv;

    @Before(LoginValidator.class)
    public void login() {
        String userName = getPara("userName");
        String userPass = getPara("userPass");
        String token = loginSrv.checkLogin(userName, userPass);
        if (StrKit.notBlank(token)) {
            HashMap<String, String> tokenMap = new HashMap<>(16);
            tokenMap.put("token", token);
            renderJson(RetTest.me.setSuccess("登录成功!", tokenMap));
            return;
        }
        renderJson(RetTest.me.setFail("用户名或密码错误!"));
    }
}
